<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label label-required">访客姓名</label>
            <div class="layui-input-block">
                <input name="vister_name" value='{$vo.vister_name|default=""}' required placeholder="请输入访客姓名" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
    <label class="layui-form-label">拜访公司</label>
    <div class="layui-input-block">
      <select name="app_company_name" lay-verify="required" id='choice_company'>
<!--         <option value=""></option>
        <option value="0">北京</option>
        <option value="1">上海</option>
        <option value="2">广州</option>
        <option value="3">深圳</option>
        <option value="4">杭州</option> -->
      </select>
    </div>
  </div>

    <div class="layui-form-item">
    <label class="layui-form-label">拜访部门</label>
    <div class="layui-input-block">
      <select name="department" lay-verify="required" id='choice_dept'>
      </select>
    </div>
  </div>

<div class="layui-form-item">
    <label class="layui-form-label">接见员工</label>
    <div class="layui-input-block">
      <select name="app_user_name" lay-verify="required" id='choice_appuser'>
      </select>
    </div>
  </div>
   
        <div class="layui-form-item nowrap">
            <label class="layui-form-label">预约日期</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input type="text" data-date-input="date" name="entry_date" value='{$vo.entry_date|default=""}' placeholder="请输入预约日期" class="layui-input">
            </div>
            <label class="layui-form-label" style="width:auto">到访日期</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input type="text" data-date-input="date" name="become_date" value='{$vo.become_date|default=""}' placeholder="请输入到访日期" class="layui-input">
            </div>
<!--             <label class="layui-form-label" style="width:auto">培训日期</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input type="text" data-date-input="date" name="leave_date" value='{$vo.leave_date|default=""}' placeholder="请输入离职日期" class="layui-input">
            </div> -->
        </div>
        <div class="layui-form-item">
  <!--           <label class="layui-form-label">联系ＱＱ</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input type="tel" autocomplete="off" name="contact_qq" value='{$vo.contact_qq|default=""}' pattern="^\d{6,}$" placeholder="请输入联系ＱＱ号码" class="layui-input">
            </div> -->
            <label class="layui-form-label">联系手机</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input type="tel" maxlength="11" autocomplete="off" name="contact_phone" value='{$vo.contact_phone|default=""}' pattern="^1[3-9][0-9]{9}$" placeholder="请输入联系手机" class="layui-input">
            </div>
            <label class="layui-form-label" style="width:auto">联系邮箱</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
                <input name="contact_mail" autocomplete="off" pattern="^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$" value='{$vo.contact_mail|default=""}' placeholder="请输入联系邮箱" class="layui-input">
            </div>
        </div>
<!--         <div class="layui-form-item">
            <label class="layui-form-label">打卡绑定</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入绑定手机" class="layui-textarea" name="mobile_macs">{$vo.mobile_macs|default=""}</textarea>
            </div>
        </div> -->
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

    <script>
        var SCOPE = {
        'get_company' : "{:url('company/company/getlist')}",
        'get_appuserlist' : "{:url('company/company/getappuserlist')}",
        'get_getdeptlist' : "{:url('company/company/getdeptlist')}",
        'jump_url' : "{:url('visitor/visitor/index')}",
    
    };


   layui.use('form',function(){

        var form=layui.form;

        console.log(form)

        var tpl_company_options = '<option value=""></option>';
        $.get(SCOPE.get_company,{},function(data,status,xhr){
    
            var companylist = JSON.parse(data)
            console.log(companylist)
            console.log(JSON.parse(data))
            for (var i = 0; i < companylist.data.length; i++) {
                tpl_company_options =   tpl_company_options+'<option value="'+companylist.data[i].id+'">'+companylist.data[i].name+'</option>'
                  
            }
             console.log(tpl_company_options)
            $('#choice_company').html(tpl_company_options)
             form.render('select');
         
        },'JSON')



        form.on('select',function(res){
            console.log(res)
            console.log(res.elem.id)
            // choice_company
        /*获取公司部门列表*/
            if(res.elem.id == 'choice_company'){
                var tpl_dept = '<option value=""></option>';
                $.get(SCOPE.get_getdeptlist,{
                "companyid":res.value

                },function(data,status,xhr){
    
                var deptlist = JSON.parse(data)
                for (var i = 0; i < deptlist.data.length; i++) {
                    tpl_dept = tpl_dept+'<option value="'+deptlist.data[i].id+'">'+deptlist.data[i].name+'</option>'
                }
                $('#choice_dept').html(tpl_dept)
                form.render('select');
                console.log(JSON.parse(data))

         
                },'JSON')
            }

        /*获取公司指定受访人*/
        // choice_appuser
            if(res.elem.id == 'choice_company'){
                var tpl_userapp = '<option value=""></option>';
                $.get(SCOPE.get_appuserlist,{
                 "companyid":res.value
        
                },function(data,status,xhr){
            
                 var appuserlist = JSON.parse(data)
                 for (var i = 0; i < appuserlist.data.length; i++) {
                     tpl_userapp = tpl_userapp+'<option value="'+appuserlist.data[i].id+'">'+appuserlist.data[i].name+'</option>'
                 }
                 $('#choice_appuser').html(tpl_userapp)
                 form.render('select');
        
                 console.log(JSON.parse(data))

         
                },'JSON')
            }
        })

   });


        window.form.render();






</script>

</form>
